package controller

import (
	"github.com/gin-gonic/gin"
	"mygin_project/service"
	"mygin_project/tool"
)

type SmsController struct {
	
}

func (sms *SmsController)Router(engine *gin.Engine)  {
	engine.GET("/api/sendcode", sms.sendSmsCode)
}

func (sms *SmsController)sendSmsCode(c *gin.Context)  {
	phone := c.DefaultQuery("phone", "")
	code := tool.SUCCESS
	if phone == "" {
		code = tool.ERROR
		c.JSON(200, gin.H{
			"status" : code,
			"message" : tool.GetErrorMsg(code),
		})
	}

	//发送验证码
	code = new(service.SmsService).SendSmsCode(phone)
	c.JSON(200, gin.H{
		"status" : code,
		"message" : tool.GetErrorMsg(code),
	})
}
